<template>
	<!-- 组件功能区 -->
<div class="vue-box">
		<div class="c-panel">
			<!-- 参数栏 -->
			<div class="c-title">检索信息</div>
			<el-form size="mini" :inline="true" @submit.native.prevent >
				<el-form-item label="机构名称：">
					<el-input v-model="p.orgname" placeholder="组织机构名称"></el-input>
				</el-form-item>
				<el-form-item style="min-width: 0px;">
					<el-button type="primary" icon="el-icon-search" @click="p.pageIndex = 1; init()">查询</el-button>
					<el-button type="primary" icon="el-icon-plus" @click="add()">添加</el-button>
				</el-form-item>
			</el-form>
			<!-- 数据列表 -->
			<div class="c-title">数据列表</div>
			<el-table :data="dataList.data" size="mini">
				<el-table-column label="id" prop="id" width="80px"></el-table-column>
				<el-table-column label="机构名称" prop="orgname"></el-table-column>
				<el-table-column label="机构地址" prop="orgaddress"></el-table-column>
				<el-table-column label="机构描述" prop="orgdesc"></el-table-column>
				<el-table-column label="创建时间" prop="createTime"></el-table-column>
				<el-table-column label="操作" width="240px">
					<template slot-scope="s">
						<el-button class="c-btn" type="success"  icon="el-icon-view" @click="get(s.row)">查看</el-button>
						<el-button class="c-btn" type="primary" icon="el-icon-edit" @click="update(s.row)">修改</el-button>
						<el-button class="c-btn" type="danger" icon="el-icon-delete" @click="del(s.row)">删除</el-button>
					</template>
				</el-table-column>
			</el-table>
			<!-- 分页 -->
			<div class="page-box">
				<el-pagination background
					layout="total, prev, pager, next, sizes, jumper" 
					:current-page.sync="p.pageIndex" 
					:page-size.sync="p.pageSize" 
					:total="p.totalCount" 
					:page-sizes="[10, 20, 30, 40, 50, 100]" 
					@current-change="init()" 
					@size-change="init()">
				</el-pagination>
			</div>
		</div>
		<orgadd ref="org-add"></orgadd>
	</div>
</template>

<script>
	//引入引页面要用到的组件，比如添加，比如修改
	import orgadd from './organizationsadd.vue'
	export default{
		components: {
			orgadd
		},
		data(){
			return {
				p:{
					"orgname":"",
					"pageIndex":1,
					"pageSize":10,
					"totalCount":0
				},
				dataList: []		// 数据集合
			}
			
		},
		methods:{
			init:function(){
				var than = this;
				this.$axios.get("/api/sysOrganizations/list",{params:{page:than.p.pageIndex,limit:than.p.pageSize,orgname:than.p.orgname}}).then(function (res){
					console.log(res.data);
					than.dataList = res.data;
					than.p.pageIndex = res.data.pageIndex;
					than.p.pageSize = res.data.pageSize;
					than.p.totalCount = res.data.totalCount;
				})
			},
			add:function (){
				this.$refs['org-add'].open(0);
			},
			update:function (t){
				this.$refs['org-add'].open(t.id);
			},
			del:function (t){
				let than = this;
				this.sa.confirm('是否删除，此操作不可撤销', function() {
					console.log(t);
					this.$axios.delete("/api/sysOrganizations/delete/"+t.id).then(function (res){
						if(res.data === 1){
							than.sa.msg("删除成功",{icon:1,time:1000});
							than.p.pageIndex = 1;
							than.init();
						}
					});
				}.bind(this));
			}
		},
		created:function (){
			this.init();
		}
	}
</script>

<style scoped>
</style>
